package org.tea.inventory.admin.web.admin;

import com.github.pagehelper.PageInfo;
import org.tea.inventory.admin.annotation.LoginAdmin;
import org.tea.inventory.base.util.ResponseUtil;
import org.tea.inventory.db.domain.ApproveHistory;
import org.tea.inventory.db.service.ApproveHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/admin/approveHistory")
public class ApproveHistoryController {

    @Autowired
    private ApproveHistoryService approveHistoryService;

    @GetMapping("/list")
    public Object list(@LoginAdmin Integer adminId,
                       String userName,
                       @RequestParam(value = "page", defaultValue = "1") Integer page,
                       @RequestParam(value = "limit", defaultValue = "10") Integer limit,
                       String sort, String order){
        if(adminId == null){
            return ResponseUtil.fail401();
        }

        PageInfo<ApproveHistory> pageInfo = approveHistoryService.queryApproveHistory(userName, page, limit, sort, order);
        Map<String, Object> data = new HashMap<>();
        data.put("total", pageInfo.getTotal());
        data.put("items", pageInfo.getList());

        return ResponseUtil.ok(data);
    }
}
